package com.lz.topic;

import com.lz.RabbitMQConnector;
import com.rabbitmq.client.CancelCallback;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;

public class ConsumerTopic {
    public static void main(String[] args) throws Exception {
        String exchangeName = "lz_exchange_topic";
        String queueName1 = "lz_queue_topic_1";
        String queueName2 = "lz_queue_topic_2";
        String queueName3 = "lz_queue_topic_3";
        String queueName4 = "lz_queue_topic_4";

        Channel channel = RabbitMQConnector.createConnectionAndChannel();


        // 接受消息的回调
        DeliverCallback deliverCallback = (consumerTage, message) -> {
            System.out.println("接收到的消息：" + new String(message.getBody()));
        };

        // 取消消息的回调
        CancelCallback cancelCallback = (consumerTag) -> {
               System.out.println("消息消费被中断");
        };
        /**
         * 消费消息
         * 1.消费哪个队列
         * 2.消费成功之后是否需要自动应答，true 表示自动应答，false 表示手动应答
         * 3.接受消息的回调
         * 4.取消消息的回调
         */
        channel.basicConsume(queueName1, true, deliverCallback,cancelCallback);
        channel.basicConsume(queueName2, true, deliverCallback,cancelCallback);
        channel.basicConsume(queueName3, true, deliverCallback,cancelCallback);
        channel.basicConsume(queueName4, true, deliverCallback,cancelCallback);

    }
}
